<?php


namespace App\Http\Controllers\Api\QrCode;


use App\Exceptions\ValidatorException;
use App\Http\Controllers\Controller;
use App\Http\Repositories\Repository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Illuminate\Support\Facades\Storage;
use Ramsey\Uuid\Uuid;

class QrCodeController extends Controller
{
    private $repository;
    public function __construct(Repository $repository)
    {
        $this->repository = $repository;
    }


    public function createQrCode(Request $request)
    {
        //随机二维码图片名
        $fileName = Uuid::uuid4()->toString() . '.png';

        //二维码图片路径
        $filename=storage_path('app/public').'/'.$fileName;

        //base64加密数据
//        $text=base64_encode('数据');
        $text=("数据\n,nimensinksandlkal");

        //创建二维码并保存二维码图片
        $res = QrCode::format('png')
            ->size(200)
            ->encoding('UTF-8')
            ->generate($text, $filename);
        ;
        dd($res);
//        Storage::disk('qrcode')->put($fileName, $res);

        dd(1);
        return Storage::disk('qrcode')->put($fileName, $res);





        $rules = [
            'file' => 'required|file|max:10240',
        ];
        $messages = [

        ];
        $validator = Validator::make($request->all(), $rules, $messages);
        if ($validator->fails()) {
            throw new ValidatorException($validator->errors()->all());
        }

//        return $this->repository->uploadFile($validator->getData());
    }
}
